<template>
  <div>
    <!-- 查询条件 -->
    <div>
      <el-select v-model="active" size="mini">
        <el-option value="0" label="全部" />
        <el-option value="1" label="有效" />
        <el-option value="-1" label="无效" />
      </el-select>
      <el-button
        style="margin-left: 6px"
        type="primary"
        size="mini"
        :loading="dataLoading"
        @click="getInfos"
      >
        查询
      </el-button>
    </div>
    <!-- 表格显示 -->
    <div style="margin-top: 8px">
      <el-table border stripe :data="infoList">
        <el-table-column prop="id" label="ID" width="100px" />
        <el-table-column prop="ruizy_code" label="系统号" />
        <el-table-column prop="admin_name" label="姓名" />
        <el-table-column prop="nickname" label="昵称" show-overflow-tooltip />
        <el-table-column prop="phone" label="联系电话" />
        <el-table-column prop="create_time" label="加入时间"></el-table-column>
        <el-table-column prop="login_phone" label="登录手机"></el-table-column>
        <el-table-column prop="expire" label="有效期"></el-table-column>
        <el-table-column label="品种权限" width="100px">
          <template #default="{ row }">
            <el-button type="text" @click="toManageUserVariety(row)">
              管理
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="详细资料" width="100px">
          <template #default="{ row }">
            <el-button type="text" @click="toShowEditUser(row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
  import { GetRoleUserInfos } from '@/api/systemManage/userInfo'
  export default {
    props: {
      role: {
        type: Number,
        required: true,
      },
    },
    data() {
      return {
        pageRole: this.role,
        active: '0',
        infoList: [],
        dataLoading: false,
      }
    },
    mounted() {
      this.getInfos()
    },
    methods: {
      getInfos() {
        this.dataLoading = true
        GetRoleUserInfos(this.pageRole, this.active).then((res) => {
          this.infoList = res.data
          this.dataLoading = false
        })
      },

      toShowEditUser(row) {
        this.$router.push({
          name: 'SysManagerUserInfo',
          query: { uid: row.id },
        })
      },
      // 管理品种权限
      toManageUserVariety(row) {
        if ([9999, 9000, 4000].indexOf(row.role) > -1) {
          this.$baseMessage('用户默认拥有所有品种权限,无需设置!', 'error')
          return
        }
        this.$router.push({
          name: 'SysAuthManagerUserVariety',
          query: { uid: row.id },
        })
      },
    },
  }
</script>
<style scoped lang="scss"></style>
